<template>
  <div class="wins-bg-new">
    <div class="wins-center">
      <el-card shadow="hover" class="wins-card-new">
        <div class="wins-title-new">
          <el-icon size="32"><Medal /></el-icon>
          <span>我的中奖记录</span>
        </div>

        <el-table :data="winList" v-if="winList.length" style="width: 100%; margin-top: 20px;">
          <el-table-column prop="prizeName" label="奖品名称" width="150" />
          <el-table-column prop="winTime" label="中奖时间" />
        </el-table>
        <el-empty v-else description="暂无中奖记录" style="margin-top: 20px;" />
        <div class="wins-link">
          <el-link type="primary" @click="$emit('to-lottery')">返回抽奖</el-link>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import axios from 'axios'
import { Medal } from '@element-plus/icons-vue'

const emit = defineEmits(['to-register', 'to-lottery', 'to-wins'])

const winList = ref([])

const getWins = async () => {
  // This is a temporary solution for demonstration. 
  // In a real application, you should get the username from the logged-in user's session or token.
  const username = 'test'; // Hardcoded for now
  if (!username) {
    winList.value = []
    return
  }
  try {
    const res = await axios.get(`http://localhost:8080/api/lottery/my-wins?username=${username}`)
    winList.value = res.data
  } catch (e) {
    winList.value = []
  }
}

getWins()
</script>

<style scoped>
.wins-bg-new {
  min-height: 100vh;
  background: url('../../anheng.png') no-repeat center center;
  background-size: cover;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wins-center {
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wins-card-new {
  border-radius: 18px;
  background: #2a2d32;
  box-shadow: 0 8px 32px 0 rgba(0,0,0,0.25);
  padding: 40px 32px 32px 32px;
  width: 500px;
  max-width: 90vw;
}

.wins-title-new {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: bold;
  margin-bottom: 28px;
  color: #fff;
  gap: 12px;
}

.wins-title-new .el-icon {
  color: #c81e2b;
}

.el-form-item__label {
  color: #fff !important;
}

.el-input__wrapper {
  background: #33373e !important;
  border: 1px solid #4a4e58 !important;
  border-radius: 8px !important;
  box-shadow: none !important;
}

.el-input__wrapper:focus-within {
  border: 1px solid #c81e2b !important;
}

.el-input__inner {
  color: #fff !important;
  background: transparent !important;
}

.el-button--primary {
  background: linear-gradient(90deg, #c81e2b 0%, #d9534f 100%);
  color: #fff;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  box-shadow: none;
  transition: background 0.3s;
  padding: 18px 0;
  font-size: 16px;
}

.el-button--primary:hover {
  opacity: 0.9;
}

.wins-link {
  margin-top: 22px;
  text-align: center;
}

.wins-link .el-link {
  color: #c81e2b;
  font-size: 16px;
}
</style>